<?php
/**
 * 内容属性管理
 */

namespace backend\controllers;


use common\models\Attributes;
use common\models\Catalog;

class AttributesController extends CommonController
{
    public function actionIndex()
    {
        $this->setQuery(Attributes::find()->orderBy("catalog_id asc"));
        return $this->query();
    }

    public function actionCreate()
    {
        $model = new Attributes();
        $this->setModel($model);

        //先只做一级栏目的，其子级栏目都是属于一级父类
        $catalogs = Catalog::find()->where("parent_id=0")->orderBy("id asc")->asArray()->all();
        $this->setParams(['catalogs' => $catalogs]);

        return $this->save();
    }

    public function actionUpdate($id)
    {
        $model = Attributes::findOne($id);
        $this->setModel($model);

        //先只做一级栏目的，其子级栏目都是属于一级父类
        $catalogs = Catalog::find()->where("parent_id=0")->orderBy("id asc")->asArray()->all();
        $this->setParams(['catalogs' => $catalogs]);

        return $this->save();
    }

    public function actionDelete()
    {
        $this->setModel(new Attributes());
        $this->delete();
    }
}